package com.itheima.d8_thread_pool;

import java.util.concurrent.*;

/*
     目标：线程池处理任务
     需求 : 使用线程池处理Callable类型任务
 */
public class ThreadPoolTest3 {
    public static void main(String[] args) throws ExecutionException, InterruptedException {
        ThreadPoolExecutor tpe = new ThreadPoolExecutor(
                3,
                5,
                60,
                TimeUnit.SECONDS,
                new ArrayBlockingQueue<>(10),
                Executors.defaultThreadFactory(),
                new ThreadPoolExecutor.AbortPolicy()
        );

        Future<Integer> submit = tpe.submit(new cla(10));
        System.out.println(submit.get());
    }
}

class cla implements Callable<Integer> {
    private int num;

    public cla() {
    }

    public cla(int num) {
        this.num = num;
    }

    int sum = 0;
    @Override
    public Integer call() throws Exception {
        for (int i = 0; i <= num; i++) {
            sum += i;
        }
        return sum;
    }
}